﻿<?php
$this->headTitle(@$this->enterprise->company_name_vn.': '.$this->translator('blog_list_page_title'));
?>
<style>
    .b_a_right{
        text-align: right;
    }
    .b_l_content{
        display: inline-block;
    }
    .b_l_content .b_title a{
        font-weight: bold;
        font-size: 10pt;
        color: #333366;
    }
    .b_l_content .b_post lable{
        font-weight: bold;
    }
    .b_l_content .b_content{
        text-align: justify;
        display: inline-block;
        width: 640px;
    }
    .b_l_content .b_action{
        margin: -5px 0 10px;
        padding-left: 105px;
    }
    .b_a_paginator{
        text-align: center;
    }

    .b_l_content .b_content span{
        text-transform: none;
    }

    *{margin:0;padding:0;}
    ol.timeline{
        list-style:none;font-size:1.2em;
    }
    ol.timeline li{
        position:relative;
        padding:.3em 0 .6em .3em;
        line-height:1.1em;
        background-color:#EFEDED;
        margin-bottom:3px;
        text-align:justify;
        display: inline-block;
        width: 97.5%
    }
    .panel { display:none; }

    .col_20{
        float: left;
        width: 20%;
    }
    .g_image{
        text-align: center;
    }
	.b_a_paginator_list{
        text-align: center;
		background-color: #EFEDED;
		line-height: 1.1em;
		margin-bottom: 3px;
		margin-left: 1em;
		padding: 0.3em 0 0.6em 0.3em;
		position: relative;
		width: 97.5%;		
		font-size: 11px;
    }
	.b_a_paginator_list .active{
		color: red;
	}	
	
</style>
<?php
    $skin_url = $this->APP_STATIC_SERVER . '/skins/'. $this->APP_TEMPLATE . '/'. $this->APP_SKIN;
?>

<?php if(!$this->found):?>
    <div class="b_a_paginator"><?php echo $this->translator('not_found_any_enterprise');?></div>
<?php else:?>

<!--Sub menu-->
<?php echo $this->widget('bizprofile','menu',array()); ?>
<!--End sub menu-->

<div class="subcolumns pb10">
    <div class="b_a_right">
        <?php if($this->allow('add') && $this->allowAction):?>

        <?php
            /**
            * Param for url;
            **/
            $arrRouteAdd = array(
                'enterprise_id' => $this->enterprise->id,
                'enterprise_name' => Tomato_Utility_String::removeSign($this->enterprise->company_name_en, '-', true)
            );
        ?>
        <a href="<?php echo $this->url($arrRouteAdd, 'b2b_blog_add');?>"><?php echo $this->translator('blog_add_btn');?></a>
        <?php endif;?>
        &nbsp;
    </div>
    <?php if($this->numBlog <= 0):?>
    <div class="b_a_paginator"><?php echo $this->translator('not_found_any_blog');?></div>
    <?php else:?>
	<!-- Được quyền xem Blog -->
    <?php if(!$this->permission || $this->permission->blog_permission  == 1 || $this->permission_viewall == 1) {?> 
    <div class="b_l_content">
    	<?php foreach ($this->blogs as $blog):?>
            <?php
                /**
                * Enterprise to view
                **/
                $enterprise = $this->enterprises[$blog->blog_id];

                /**
                * Param for url;
                **/
                $arrRouteView = array(
                    'enterprise_id' => $this->enterprise->id,
                    'enterprise_name' => Tomato_Utility_String::removeSign($this->enterprise->company_name_en, '-', true),
                    'blog_id' => $blog->blog_id,
                    'slug' => $blog->slug,
                );
                
                /**
                 * Enterprise route
                 */
                $arrRouteEn = array(
                    'enterprise_id' => $enterprise->id,
                    
                    'enterprise_name' => Tomato_Utility_String::removeSign($enterprise->company_name_en, '-', true),                    
                );
            ?>
            <div class="title" id="blogTitle_<?php echo $blog->blog_id;?>">
                <a style="color:#FF9900" href="<?php echo $this->url($arrRouteView, 'b2b_blog_view'); ?>"><?php echo $blog->title;?></a>
            </div>
            <div class="b_post">
                <lable><?php echo $this->translator('blog_post_by');?></lable>
                
                <?php /*////////////////////////////////////////////*/?>
                <a href="<?php echo $this->url($arrRouteEn, 'bizprofile_enterprise_index');?>">
                	<?php echo isset($enterprise->company_name_vn)?$enterprise->company_name_vn:null;?>
                </a>
                
                
                (<?php echo date('d-m-Y', strtotime($blog->date));?>)
            </div>
            <div class="b_link"><a href="http://<?php echo $blog->link;?>"><?php echo $blog->link;?></a></div>
            <div class="b_content">
                <div style="width:17%; float:left; display:inline-block;">
                    <?php
                        /**
                        * Check image exist directory
                        **/
                        $file = $this->APP_STATIC_SERVER.'/images/logos/'.$blog->enterprise_id.'.jpg';
                        $path = str_replace($this->APP_STATIC_SERVER,getcwd(),$file);
                        if(!is_file($path)){
                            $file = $this->APP_STATIC_SERVER.'/images/logos/no-logo.jpg';
                        }

                        /**
                         * Comment foreach blog to view
                        **/
                        $comments = isset($this->arrComments[$blog->blog_id])?$this->arrComments[$blog->blog_id]:null;

                        /**
                         * User and enterprise for comment this blog to view
                        **/
                        $arrUEComments = $this->arrUEComments[$blog->blog_id];
                    ?>
                    <a href="<?php echo $this->url($arrRouteEn, 'bizprofile_enterprise_index');?>">
                    	<img width="100" src="<?php echo $file;?>" />
                    </a>
                </div>
                <div style="width:83%; float:left; display:inline-block" id="blogContent_<?php echo $blog->blog_id;?>">
                    <span><?php echo Tomato_Helper_Helper::substring($blog->content, 500);?></span>
                </div>
            </div>
            <div class="b_action">
                <a href="<?php echo $this->url($arrRouteView, 'b2b_blog_view'); ?>"><?php echo $this->translator('blog_view_full')?></a>&nbsp;&nbsp;&nbsp;&nbsp;
                <?php if(count($comments) > 0):?>
                <a class="comment_button" id="<?php echo $blog->blog_id;?>" href="javascript:void(0)"><?php echo $this->translator('blog_view__full_comment');?> <?php echo count($comments);?> <?php echo $this->translator('blog_comment_list')?></a>
                <?php else:?>
						<?php 
							$auth = Zend_Auth::getInstance();
							if ($auth->hasIdentity()):
						?> 
						<a href="<?php echo $this->url($arrRouteView, 'b2b_blog_view'); ?>/?comment=true"><?php echo $this->translator('blog_click_to_comment')?></a>
						<?php endif;?>
                <?php endif;?>
                <?php if($blog->language != $this->lang):?>
                &nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void(0);" class="blogTranglate" rel="<?php echo $blog->blog_id;?>"><?php echo $this->translator('blog_translated')?></a><span id="s_loading_<?php echo $blog->blog_id;?>"></span>
                <?php endif;?>
            </div>
            <div style="padding-left:75px;">
                <ol id="update" class="timeline">
					<div class='panel' id="slidepanel<?php echo $blog->blog_id;?>">
						<?php 
							$auth = Zend_Auth::getInstance();
							if ($auth->hasIdentity()):
						?> 
							<li>
									<div style="font-size:11px; text-align: center;">
										<a href="<?php echo $this->url($arrRouteView, 'b2b_blog_view'); ?>/?comment=true"><?php echo $this->translator('blog_click_to_comment');?></a>
									</div>
							</li>
						<?php endif;?>
						<div id="outPut_<?php echo $blog->blog_id;?>">
							<?php foreach($comments as $comment):?>
							<li id="comment_content_<?php echo $comment->id;?>">
								<div style="float:left; width:45px;">
									<?php
										/**
										* User of commment to view
										**/
										$cUI = isset($arrUEComments[$comment->id])?$arrUEComments[$comment->id]:null;

										$showLink  = false;
										if(isset($cUI['enterprise']->id))
											if($cUI['enterprise']->frontend_active == 1 && $cUI['enterprise']->deleted != 1) 
												$showLink = true;
										$showStatus = isset($cUI['enterprise']->id)?true:false;
										$deleted = (isset($cUI['enterprise']->deleted) && $cUI['enterprise']->deleted == 1)? true : false;
										$frontend_active  = (isset($cUI['enterprise']->frontend_active) && $cUI['enterprise']->frontend_active == 1)? true : false;
										/**
										* Check image exist directory
										**/									
										if(isset($cUI['enterprise']->id)){                                    
											$file = $this->APP_STATIC_SERVER.'/images/logos/'.$cUI['enterprise']->id.'.jpg';
											$path = str_replace($this->APP_STATIC_SERVER,getcwd(),$file);
											if(!is_file($path)){
												$file = $this->APP_STATIC_SERVER.'/images/logos/no-logo.jpg';
											}
										}
										/**
										 * Enterprise route
										 */
										if($deleted==false && $frontend_active ==true){
											$arrRouteEn = array(
												'enterprise_id' => $cUI['enterprise']->id,
												
												'enterprise_name' => Tomato_Utility_String::removeSign($cUI['enterprise']->company_name_vn, '-', true),                    
											);																		
									?>
									<a href="<?php echo $this->url($arrRouteEn, 'bizprofile_enterprise_index');?>"><img width="40" src="<?php echo $file;?>" /></a>
									<?php }else{?>
										<!--img width="40" src="<?php // echo $file;?>" /-->
										<div style="width: 40px; float: left;">&nbsp;</div>
									<?php }?>
								</div>
								<div align="left" style="float:left; width:475px; font-size:11px;">
									<?php 
										if(isset($cUI['enterprise']->id)){
											$arrRouteEn = array(
												'enterprise_id' => $cUI['enterprise']->id,					                    
												'enterprise_name' => Tomato_Utility_String::removeSign($cUI['enterprise']->company_name_vn, '-', true),                    
											);							
										}									
										if($cUI['user'])
										{
											$arrUser = array(
						                    'user_name' => $cUI['user']->user_name,					                    
						                		);
										}
										
									?>							
									<?php if($deleted==false && $frontend_active ==true){?>
									<a href="<?php echo $this->url($arrRouteEn, 'bizprofile_enterprise_index');?>">
										<?php echo ($cUI['user']->full_name)?$cUI['user']->full_name:$cUI['user']->user_name;?>
										<?php echo ($cUI['enterprise'])?', '.$cUI['enterprise']->company_name_vn:null;?>
									</a>
									<?php }else{?>
										<?php if($cUI['user']):?>
											<a href="<?php echo $this->url($arrUser, 'customer_customer_list');?>">
											<?php if($cUI["user"]) echo ($cUI['user']->full_name)?$cUI['user']->full_name:$cUI['user']->user_name;?>
											</a>
										<?php endif;?>
									<?php }?>
									<br/>
									<?php echo $comment->content;?>
									<br/>
									<label style="font-size:10px; color:#555555;"><?php echo date('h:i:s d/m/Y', strtotime($comment->date));?></label>
								</div>
								<?php if(@$this->user->enterprise->id == $blog->enterprise_id):?>
								<!--<div style="float:left; width:10px; margin-top:-5px; padding-left:5px;">
									<a href="javascript:void(0)" class="del_comment" rel="<?php echo $comment->id;?>">
										<b>x</b>
									</a>
								</div>-->
								<?php endif;?>
								<?php if($showStatus):?>
									<?php if($deleted):?>
										<span style="margin-left:42px;color:red;font-size:11px;"><?php echo $this->translator("blog_view_enterprise_non_exist");?></span>
									<?php endif; ?>
									<?php if(!$deleted && !$frontend_active):?>
										<span style="margin-left:42px;color:#BC8F8F;font-size:11px;"><?php echo $this->translator("blog_view_enterprise_inactive");?></span>
									<?php endif; ?>
								<?php endif;?>
								
							</li>
							<?php endforeach;?>
						</div>
						<!-- 
							Name : Cong Ngo
							Date  : 05/05/2011
							Ph�n trang b?ng jquery d? li?u d� du?c load l�n h?t r?i,
							ch? ?n di v� cho hi?n l�n th�i.
						-->
						<div class="b_a_paginator_<?php echo $blog->blog_id;?> b_a_paginator_list">
						</div>
						<script language="javascript">							
							function showItem<?php echo $blog->blog_id;?>(offset,count){
								$("#outPut_<?php echo $blog->blog_id;?>").find("li").hide();
								var i = 0;
								$("#outPut_<?php echo $blog->blog_id;?>").find("li").each(function(){
									if(i>=offset && i < offset+count)
									   $(this).show();
									i++;
								});
							}
							function getOffset<?php echo $blog->blog_id;?>(page,perPage){
								return (perPage * (page-1) < 0)? 0 : perPage * (page-1);
							}
							function getMaxPage<?php echo $blog->blog_id;?>(){
								var total  = $("#outPut_<?php echo $blog->blog_id;?>").find("li").size();
								return Math.floor(total/<?php echo $this->perPage?>) + ((total % <?php echo $this->perPage?> != 0)?1:0);
							}
							function registerPerpage<?php echo $blog->blog_id;?>(currentPage){								
								var maxPage = getMaxPage<?php echo $blog->blog_id;?>();
								var html = '';
								if(maxPage>1){
									for(var i =1;i <= maxPage; i++){
										var classs = "";
										if(i == currentPage) classs = "active";										
										html += '<a href="#" class="' + classs + '" name="page-'+i+'">'+i+'</a>&nbsp;';									
									}
									$(".b_a_paginator_<?php echo $blog->blog_id;?>").html(html);
									var offset = getOffset<?php echo $blog->blog_id;?>(currentPage,<?php echo $this->perPage?>);
									showItem<?php echo $blog->blog_id;?>(offset,<?php echo $this->perPage?>);
									$(".b_a_paginator_<?php echo $blog->blog_id;?>").find("a").unbind("click");
									$(".b_a_paginator_<?php echo $blog->blog_id;?>").find("a").bind("click",function(){
										if($(this).hasClass("active")==false){
											$(".b_a_paginator_<?php echo $blog->blog_id;?>").find(".active").removeClass("active");
											$(this).addClass("active");										
											var page = $(this).attr("name") + "";
											var page = page.replace("page-","");
											var offset  =  getOffset<?php echo $blog->blog_id;?>(page,<?php echo $this->perPage?>);										
											showItem<?php echo $blog->blog_id;?>(offset,<?php echo $this->perPage?>);										
										}									
										return false;
									});
									$(".b_a_paginator_<?php echo $blog->blog_id;?>").find("a").removeClass("active");
									$(".b_a_paginator_<?php echo $blog->blog_id;?>").find("a:eq("+(currentPage-1)+")").addClass("active");
									$(".b_a_paginator_<?php echo $blog->blog_id;?>").show();
								}else{
									$(".b_a_paginator_<?php echo $blog->blog_id;?>").hide();
								}
							}
							$(document).ready(function(){
								registerPerpage<?php echo $blog->blog_id;?>(<?php echo $this->pageIndex?>);
							});
						</script>						
						<!--
							******** END SCRIPT *************
						-->						
					</div>
                </ol>
            </div>
        <?php endforeach;?>
    </div>
     
    <div class="b_a_paginator">
        <?php echo $this->paginator()->slide($this->paginator, $this->paginatorOptions);?>
    </div>
    
	<?php  }else{?>   <!-- Không được quyền xem Blog -->
		<div class="b_l_content" width="640">
	    	<?php  echo $this->translator("permisson_blog_allow_view_blog"); ?>
	   	</div>
	   	
	<?php  }?>
    <script src="<?php echo $skin_url; ?>/html/js/jquery.translate.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function() {

            /**
            * Auto translate
            */
            $(".blogTranglate").click(function(){
                id = $(this).attr('rel');
                $('#s_loading_'+id).addClass('t_a_ui_helper_loading');
                $("#blogTitle_"+id).translate('en');
                $("#blogContent_"+id).translate('en',{
                                        complete:function(){
                                            //console.log( this.translation );
                                            $('#s_loading_'+id).removeClass('t_a_ui_helper_loading');
                                        }}
                            );
            })

            /**
            * Comment show or close form
            */
            $(".comment_button").click(function(){
                var element = $(this);
                var I = element.attr("id");

                $("#slidepanel"+I).slideToggle(300);
                $(this).toggleClass("active");

                return false;
            });
        });
    </script>
    <?php endif;?>
</div>
<?php endif;?>

